package com._13read.rss.util;

import cn.hutool.http.HttpUtil;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;
import lombok.extern.slf4j.Slf4j;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.List;

/**
 * rss 工具类
 */
@Slf4j
public class RssUtil {

    public static SyndFeed getSyndFeed(String urlString) throws IOException,FeedException {
        URL url = new URL(urlString);
        XmlReader reader = new XmlReader(url);
        SyndFeedInput input = new SyndFeedInput();
        SyndFeed feed = input.build(reader);
        return feed;
    }

    public static List<SyndEntry> getEntries(SyndFeed feed){
        List<SyndEntry> entries = feed.getEntries();
        return entries;
    }

}
